package utils

import (
	"gopkg.in/mgo.v2/bson"
	"fmt"
	"encoding/json"
)

func Guid() string {
	return bson.NewObjectId().Hex()
}

func PtrOfInt(i int) *int {
	return &i
}

func PtrOfString(i string) *string {
	return &i
}

func PtrOfInt64(i int64) *int64 {
	return &i
}

func PtrOfFloat64(i float64) *float64 {
	return &i
}

func InterfaceOfString(i interface{}) string {

	if i == nil {
		return ""
	}

	return i.(string)
}

func InterfaceOfInt64(i interface{}) int64 {

	if i == nil {
		return 0
	}
	return i.(int64)
}

func StrContains(src []string, tag string) bool {
	for _, s := range src {
		if s == tag {
			return true
		}
	}
	return false
}

func Println(obj interface{}) {
	oo, err := json.Marshal(obj)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(oo))
}
